//
//  MainViewController.m
//  ECO
//
//  Created by 谷银行 on 2019/9/23.
//  Copyright © 2019 谷银行. All rights reserved.
//

#import "MainViewController.h"
#import "YourTestChatViewController.h"
@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self tabbar];
}
- (void)tabbar{
    NSArray *array = @[@"消息",@"设置"];
    NSArray *VCarr = @[@"YourTestChatViewController",@"SetViewController"];
    NSArray *arr1=@[@"tab_icon_new",@"tab_icon_setup"];
    NSArray *arr2=@[@"tab_icon_new up",@"tab_icon_set up"];
    NSMutableArray *MutableArr = [[NSMutableArray alloc]init];
    for (int i=0; i<VCarr.count; i++) {
        //字符串来创建控制器   string->controller
        UIViewController *vc=[[NSClassFromString(VCarr[i]) alloc]init];
        //添加导航控制器
        UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:vc];
        //设置Tabbaritem的  选中图片 未选中图片 标题
        nav.title=array[i];
        [[UITabBarItem appearance]setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithHexString:@"#999999"],NSForegroundColorAttributeName,[UIFont fontWithName:@"Helvetica"size:12.0f],NSFontAttributeName,nil]forState:UIControlStateNormal];
        //字体大小，颜色（被选中时）
        [[UITabBarItem appearance]setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithHexString:@"#00C6AC"],NSForegroundColorAttributeName,[UIFont fontWithName:@"Helvetica"size:12.0f],NSFontAttributeName,nil]forState:UIControlStateSelected];
        // 未选中
        nav.tabBarItem.image=[[UIImage imageNamed:arr1[i]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        // 被选中
        nav.tabBarItem.selectedImage=[[UIImage imageNamed:arr2[i]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        // 去除tabbar上的黑线
        CGRect rect = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width);
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
        CGContextFillRect(context, rect);
        UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        [[UITabBar appearance]setBackgroundImage:img];
        [[UITabBar appearance]setShadowImage:img];
        [[UITabBar appearance] setBarTintColor:[UIColor colorWithHexString:@"#FFFFFF"]];
        // 去除nav下的黑线
        [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"Image"] forBarMetrics:UIBarMetricsDefault];
        [[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:@"Image"]];
        //添加到数组里
        [MutableArr addObject:nav];
    }
    self.viewControllers = MutableArr;
}

@end
